<template>
  <div class="wrap">
    <div class="title">
      <div class="task-name">
        <span class="name">评分任务名称：</span>
        <span class="value">{{taskName}}</span>
        <el-button class="clear-task" type="danger" @click="clearTask">清空所有评分</el-button>
      </div>
      <div class="model-name">
        <span class="name">评分模型名称：</span>
        <span class="value">{{modelName}}</span>
      </div>
    </div>
    <div class="org-list">
      <div
        class="org-item"
        v-for="item of orgList"
        :key="item.orgId"
        @click="clickOrg(item.orgId)"
        :class="item.orgId === selectedOrgId ? 'active': ''"
      >
        <div class="org-name">{{item.orgName}}</div>
        <div class="item-count">已评项目：{{item.markItemCount}}/{{totalItemCount}}</div>
        <div class="item-score">得分：{{item.markScore}}/{{totalScore}}</div>
      </div>
    </div>
    <div class="score-item">
      <score-item @mark="mark" :taskId="taskId" :orgId="selectedOrgId" :orgName="selectedOrgName"></score-item>
    </div>
  </div>
</template>
<script>
import { getScoreMarkOrgInfo, clearScoreTaskItem } from "@/api/score.js";
import ScoreItem from "./components/ScoreItem";
import { Button } from "element-ui";
export default {
  name: "score-mark",
  components: {
    [Button.name]: Button,
    ScoreItem
  },
  data() {
    return {
      taskId: null,
      taskName: null,
      modelId: null,
      modelName: null,
      totalItemCount: null,
      totalScore: null,
      orgList: [],
      selectedOrgId: null,
      selectedOrgName: null
    };
  },
  mounted() {
    this.taskId = this.$route.params.id;
    this.refreshOrgList();
  },
  methods: {
    refreshOrgList() {
      getScoreMarkOrgInfo(this.taskId)
        .then(res => {
          this.taskName = res.taskName;
          this.modelId = res.modelId;
          this.modelName = res.modelName;
          this.totalItemCount = res.totalItemCount;
          this.totalScore = res.totalScore;
          this.orgList = res.scoreOrgMarkInfoList;
        })
        .catch(errMsg => this.$alert(errMsg.msg));
    },
    clickOrg(orgId) {
      this.selectedOrgId = orgId;
      this.selectedOrgName = this.orgList.find(
        item => item.orgId === orgId
      ).orgName;
    },
    mark() {
      this.refreshOrgList();
    },
    clearTask() {
      this.$confirm("永久删除所有评分, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          clearScoreTaskItem(this.taskId)
            .then(res => {
              this.refreshOrgList();
              this.selectedOrgId = null;
              this.selectedOrgName = null;
            })
            .catch(errMsg => this.$alert(errMsg.msg));
        })
        .catch(() => {});
    }
  }
};
</script>
<style lang="stylus" scoped>
.wrap {
  margin-left: 5px;

  .title {
    font-weight: bold;
    font-size: 18px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ccc;
    padding-top: 15px;

    .task-name {
      margin-bottom: 10px;

      .name {
        color: white;
        border-radius: 8px;
        background-color: #222;
      }

      .value {
        color: #666;
      }

      .clear-task {
        margin-left: 15px;
      }
    }

    .model-name {
      padding-left: 20px;

      .name {
        color: white;
        border-radius: 8px;
        background-color: #67C23A;
      }

      .value {
        color: #666;
      }
    }
  }

  .org-list {
    padding-top: 20px;
    padding-left: 20px;
    position: absolute;
    width: 250px;
    background-color: #ccc;

    .org-item {
      cursor: pointer;
      border-bottom: 1px solid #ccc;
      margin-bottom: 3px;

      &.active {
        background-color: #67C23A;
        color: white;
      }

      &:hover {
        background-color: #E6A23C;
        color: white;
      }

      .org-name {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 5px;
      }

      .item-count {
        font-size: 14px;
        color: #444;
        padding-left: 3px;
      }

      .item-score {
        font-size: 14px;
        color: #444;
        padding-left: 3px;
      }
    }
  }

  .score-item {
    padding-left: 300px;
  }
}
</style>